package reflection;

import org.junit.Test;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * @author 吴阳基
 * @datetime 2024/1/3 13:50
 */
public class ShiLi4 {
    @Test
    public void test(){
        Field[] fields = Person.class.getDeclaredFields();
        System.out.println("==========属性展示===========");
        for (Field field : fields) {
            System.out.println("属性名"+field.getName());
            System.out.println("属性类型"+field.getType().getName());
            System.out.print("访问修饰符：");
            int modifiers = field.getModifiers();

            if ((modifiers & Modifier.STATIC) == Modifier.STATIC){
                System.out.println("static");
            }
            if ((modifiers & Modifier.FINAL) == Modifier.FINAL){
                System.out.println("final");
            }
            if ((modifiers & Modifier.PRIVATE) == Modifier.PRIVATE){
                System.out.println("private");
            }
            if ((modifiers & Modifier.PROTECTED) == Modifier.PROTECTED){
                System.out.println("protected");
            }
            if ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC){
                System.out.println("public");
            }
            System.out.println("--------------------------");
        }
    }
}
